package cn.ec.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
/*jedis工具类*/

public final class JedisPool {
    private JedisPool() {
    }

    private final static redis.clients.jedis.JedisPool jedisPool;
    private final static int MAX_TOTAL = 10;
    private final static int MAX_WAIT_MILLIS = 3000;
    private final static String HOST = "lucky-bin.cn";
    private final static int PORT = 6379;
    private final static String PASSWORD = "lyb123456";


    /*创建连接池*/
    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(MAX_TOTAL);
        jedisPoolConfig.setMaxWaitMillis(MAX_WAIT_MILLIS);
        jedisPool = new redis.clients.jedis.JedisPool(jedisPoolConfig, HOST, PORT, 1000, PASSWORD);
    }

    /*获取jedis*/
    public static Jedis getJedis() {
        return jedisPool.getResource();
    }

    /*关闭Jedis*/
    public static void close(Jedis jedis) {
        if (jedis != null) {
            jedis.close();
        }
    }
}